package com.mycloud.annotation.process;

import com.mycloud.annotation.MyData;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.ExecutableType;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;

@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes("com.mycloud.annotation.MyData")
public class MyProcessor extends AbstractProcessor {
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        System.out.println("生成代码");
        try {
            writeBuilderFile();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
                // 返回false 表示 当前处理器处理了之后 其他的处理器也可以接着处理，返回true表示，我处理完了之后其他处理器不再处理
                return false;


    }


    private void writeBuilderFile() throws IOException, IOException {

        JavacFiler builderFile = (JavacFiler)processingEnv.getFiler();
        JavaFileObject javaFileObject = builderFile.createSourceFile("com.mybatis.flex.entity.Acc");
        try (PrintWriter out = new PrintWriter(javaFileObject.openWriter())) {
                out.print("package ");
                out.print("com.mybatis.flex.entity");
                out.println(";");
                out.println();
            out.print("public class ");
            out.print("Acc");
            out.println(" {");
            out.println("}");
        }
        builderFile.close();
    }
}
